Fix: Reuse untitled session when new story is created#164
Conversation
Add POST /api/terminal/rename endpoint that moves a PTY session entry to a new key without killing the process. Frontend polling now calls rename instead of letting a new session auto-create, preserving the Claude conversation context. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
project7-interns
left a comment
There was a problem hiding this comment.
Verdict: REQUEST CHANGES
Summary
The PR is close, but the rename flow still has two blocking session-lifecycle bugs. One leaves renamed PTY entries stuck in the active-session map after the process exits, and the other still allows a second session to spawn if the async rename does not complete before selection changes.
Findings
- [high] Renaming the
ptySessionsmap key does not update the exit handler's lookup key, so a renamed session is no longer cleaned up when the PTY exits.- File:
app/routes/terminal.ts:203 - Suggestion: store the current story/session key on the session object or otherwise make the
term.onExitcleanup follow the renamed key before moving the map entry.
- File:
- [high] The new-story polling path fires
renameRef.current(oldName, name)without awaiting success, then immediately removes the untitled entry and selects the new story.- File:
app/web/components/StoriesPage.tsx:90 - Suggestion: await the rename result and only switch selection / consume the untitled session after the rename succeeds; otherwise a slow or failed rename can still auto-spawn a second
paper-chairsession while the original untitled PTY keeps running.
- File:
Decision
Requesting changes because the current implementation can still orphan or duplicate sessions, which violates the issue's acceptance criteria around reusing the original Untitled PTY.
@re2 Review — REQUEST CHANGESOverall the approach is clean — rename-in-place is the right call for preserving the PTY process and Claude conversation context. One issue needs fixing: 🔴 Missing server-side guard for existing
|
…session - onExit handler now finds session by term reference instead of captured storyName, so cleanup works after rename - StoriesPage awaits rename result and only consumes the untitled session on success, preventing orphaned PTYs on failure Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
project7-interns
left a comment
There was a problem hiding this comment.
Verdict: REQUEST CHANGES
Summary
The original rename-lifecycle bugs are fixed on the current head, but one backend blocker remains in the rename endpoint.
Findings
- [high]
POST /api/terminal/renamestill does not rejectnewNamewhen that target session key already exists inptySessions, so a duplicate/racy rename can overwrite a live session entry and orphan its PTY.- File:
app/routes/terminal.ts:206 - Suggestion: add an explicit guard before moving the map entry, e.g. return
409whenptySessions.has(newName).
- File:
Decision
Keeping this in request-changes state until the rename endpoint protects against collisions. The earlier cleanup/await fixes look correct.
Reject rename when target session already exists in ptySessions to prevent overwriting a live session and orphaning its PTY. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
project7-interns
left a comment
There was a problem hiding this comment.
Verdict: COMMENT
Summary
The current head addresses the remaining rename-collision blocker. I found no further code issues in the rename/session-reuse flow.
Findings
- No remaining code blockers on the current diff.
Decision
Holding final approval until the current lint-and-typecheck run is green.
project7-interns
left a comment
There was a problem hiding this comment.
Verdict: APPROVE
Summary
The rename/session-reuse implementation now satisfies issue #162. The current head fixes the session cleanup, async rename sequencing, and rename-collision handling.
Findings
- No remaining blocking issues.
Decision
Approving because the implementation meets the acceptance criteria and lint-and-typecheck passed on the current head.
@re2 Re-review — APPROVE ✅All issues addressed across the three commits:
CI ( APPROVE |
Summary
POST /api/terminal/renamebackend endpoint that moves a PTY session entry to a new key without killing the processFixes #162
Test plan
🤖 Generated with Claude Code